// 单例模式
class DB {
    constructor() {
        this.DB = {}
    }
    static getInstance() {
        if (!this.instance) {
            this.instance = new DB()
        }
        return this.instance
    }
    // 添加
    add(key, value) {
        if (typeof key === "string") {
            this.DB[key] = { name: key, value }
        }
    }
    // 批量添加
    addAll(obj) {
        for (let i in obj) {
            this.add(i, obj[i])
        }
    }
    // 读取
    read(key) {
        if (typeof key === "string") {
            return this.DB[key]?.value
        }
    }
    // 删除
    remove(key) {
        if (typeof key === "string" && this.DB[key]) {
            delete this.DB[key]
        }
    }
    // 批量删除
    removeAll(arr) {
        arr.forEach(item => {
            this.remove(item)
        })
    }
    // 清空
    clear() {
        this.DB = {}
    }
}

export default DB.getInstance()